package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.SensitiveSelectDto;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.wemedia.service.WmSensitiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/api/v1/sensitive")
public class WmSensitiveController {

    @Autowired
    private WmSensitiveService wmSensitiveService;

    @PostMapping("/list")
    public ResponseResult list(@RequestBody SensitiveSelectDto dto){
        return wmSensitiveService.selectAll(dto);
    }

    @PostMapping("/save")
    public boolean save(@RequestBody WmSensitive sensitive) {
        sensitive.setCreatedTime(new Date());
        return wmSensitiveService.save(sensitive);
    }

    @DeleteMapping("/del/{id}")
    public boolean delete(@PathVariable("id") Integer id){
        boolean b = wmSensitiveService.removeById(id);
        return b;
    }

    @PostMapping("/update")
    public boolean update(@RequestBody WmSensitive sensitive) {
        sensitive.setCreatedTime(new Date());
        boolean flag = wmSensitiveService.updateById(sensitive);
        return flag;
    }

}
